<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * This file contains the Domain_Store_Process class.
 *
 * PHP version 5
 *
 * This file is part of Majic - A rapid-development web application framework
 * for PHP 5.
 *
 * Majic is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * Majic is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Majic. If not, see <http://www.gnu.org/licenses/>.
 *
 * @package     Domain
 * @author      Michael J. I. Jackson <mjijackson@gmail.com>
 * @copyright   2007-2008 Michael J. I. Jackson
 * @license     http://www.gnu.org/licenses/lgpl-3.0.txt GNU LGPL 3.0
 * @version     SVN: $Id: Process.php 34 2008-07-19 04:50:53Z mjijackson $
 */

/**
 * A domain store for a process-level cache.
 *
 * @package     Domain
 * @author      Michael J. I. Jackson <mjijackson@gmail.com>
 */
class Domain_Store_Process extends Domain_Store
{

    /**
     * A map that will be used to store the objects.
     *
     * @var     array
     * @access  private
     */
    private $objs = array();

    /**
     * @see     Domain_Store::add()
     */
    public function add($key, Domain_Object $obj)
    {
        if (!isset($this->objs[$key])) {
            $this->objs[$key] = $obj;
        }
    }

    /**
     * @see     Domain_Store::set()
     */
    public function set($key, Domain_Object $obj)
    {
        $this->objs[$key] = $obj;
    }

    /**
     * @see     Domain_Store::find()
     */
    public function find($key)
    {
        return isset($this->objs[$key]) ? $this->objs[$key] : null;
    }

    /**
     * @see     Domain_Store::save()
     */
    public function save()
    {
        foreach ($this->objs as $obj) {
            $obj->save();
        }
    }

}

?>
